var prefix = jsctx + "/acctTenantOperator";

var acctTenantOperator = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 40;

    // var pageNumber = sessionStorage.getItem("pageNumber",)
    function load() {
        // alert($('#exampleTable').bootstrapTable('getOptions').pageNumber);
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageAcctTenantOperator",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 20,
                    pageList: [20],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    height: h,
                    showColumns: true,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            operatorName: $('#operatorName').val(),
                            contactName: $('#contactName').val(),
                            loginName: $('#loginName').val()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'tenantOperatorCode', title: '分销商编号', width: '100'},
                        {field: 'operatorName', title: '分销商名称', width: '150'},
                        {field: 'loginName', title: '登录账号', width: '100'},
                        {field: 'contactName', title: '联系人', width: '100'},
                        // {field: 'address', title: '公司地址', width: '100'},
                        {field: 'status', title: '状态', width: '100'},
                        {field: 'createdTime', title: '创建时间', width: '100'},
                        {
                            title: '操作',
                            field: 'roleId',
                            width: '300', align: 'center',
                            formatter: function (value, row, index) {
                                var a = '';
                                var b = '';
                                var d = '';
                                if (FinanceManage_tenantOperator_update) {
                                    a = '<a class="btn btn-success btn-sm ' + has_edit + '" href="#" title="站点列表" onclick="acctTenantOperator.acctTenantOperatorElecStation(\''
                                        + row.tenantOperatorCode
                                        + '\')">站点列表</a> ';
                                    b = '<a class="btn btn-success btn-sm" href="#" title="对账单" onclick="acctTenantOperator.acctBillOrder(\''
                                        + row.tenantOperatorCode
                                        + '\')">对账单</a> ';
                                    d = '<a class="btn btn-success btn-sm ' + has_edit + '" href="#" title="结算配置" onclick="acctTenantOperator.acctBank(\''
                                        + row.tenantOperatorCode
                                        + '\')">结算配置</a> ';
                                }
                                // var c = '<a class="btn btn-success btn-sm" href="#" title="结算总览" onclick="acctTenantOperator.acctDetail(\''
                                //     + row.tenantOperatorCode
                                //     + '\')">结算总览</a> ';
                                return a + b + d;
                            }
                        }
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        location.href = prefix + "/index";
    }

    function acctTenantOperatorElecStation(tenantOperatorCode) {
        location.href = prefix + "/acctTenantOperatorElecStation/" + tenantOperatorCode;
    }

    function acctBank(tenantOperatorCode) {
        location.href = prefix + "/acctBank/" + tenantOperatorCode;
    }


    function acctBillOrder(tenantOperatorCode) {
        location.href = prefix + "/acctBillOrder/" + tenantOperatorCode;
    }


    function acctDetail(tenantOperatorCode) {
        location.href = prefix + "/acctDetail/" + tenantOperatorCode;
    }

    function acctWithdrawApply() {
        location.href = prefix + "/acctWithdrawApply";
    }

    function exportAcctTenantOperator() {
        $.fileDownload(jsctx + "/tenantOperator/exportTenantOperator", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                operatorName: $("#operatorName").val().trim(),
                loginName: $("#loginName").val().trim(),
                contactName: $("#contactName").val().trim(),
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        acctTenantOperatorElecStation: acctTenantOperatorElecStation,
        acctBank: acctBank,
        acctBillOrder: acctBillOrder,
        acctDetail: acctDetail,
        acctWithdrawApply: acctWithdrawApply,
        exportAcctTenantOperator: exportAcctTenantOperator
    };
})();
